package com.uenpay.im.ui.old.activity.stickers;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.utils.StringUtils;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 添加表情
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class AddStickerInvokItem extends HttpInvokeItem {

	public class AddStickerInvokItemResult {
		public int status;
		public String msg;
		public String favoriteid;
	}

	public AddStickerInvokItemResult getOutput() {
		return (AddStickerInvokItemResult) GetResultObject();
	}

	public AddStickerInvokItem(String fileJson) {
		String url = APIConfiguration.getBaseUrl() + "Chat/Chat/faceAdd?img="
				+ StringUtils.encodeParams(fileJson) + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		AddStickerInvokItemResult result = new AddStickerInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject jsonObject = json.optJSONObject("data");
			if (jsonObject != null && jsonObject.has("favoriteid")) {
				result.favoriteid = jsonObject.optString("favoriteid");
			}

		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}
		return result;
	}

}
